{% extends 'base.html.twig' %}
{% import 'Import/app_import.html.twig' as appImport %}

{% block head_title %}{{ 'snapshots'|trans }} - {{ snapshot.name }}{% endblock %}

{% block heading_1 %}
    {{ appImport.heading({'level': 1, 'title': 'snapshots'|trans, 'link': {'url': path('snapshots')}}) }}
{% endblock %}

{% block heading_2 %}
    {{ appImport.heading({'level': 2, 'title': snapshot.name, 'badge': {'title': snapshot.state|trans, 'context': snapshot.state}}) }}
{% endblock %}

{% block tabs %}
    {% include 'Modules/snapshot/snapshot_read_tabs.html.twig' with {'active': 'summary'} %}
{% endblock %}

{% block main_content %}
    {% embed 'Embed/block_embed.html.twig' %}
        {% import 'Import/app_import.html.twig' as appImport %}
        {% block content %}
            {{ appImport.heading({'level': 3, 'title': 'summary'|trans}) }}

            {% embed 'Embed/buttons_embed.html.twig' %}
                {% import 'Import/app_import.html.twig' as appImport %}
                {% block content %}
                    {% if is_granted('SNAPSHOT_DELETE', snapshot) %}
                        {{ appImport.buttonModal({
                            'id': 'SnapshotDelete',
                            'title': 'delete'|trans,
                            'body': snapshot.name,
                            'href': path('snapshots_delete', {'repository': snapshot.repository, 'snapshot': snapshot.name}),
                        }) }}
                    {% endif %}
                {% endblock %}
            {% endembed %}

            <hr>

            <div class="row">
                {{ appImport.dashboardKpi({'title': 'state'|trans, 'badge': {'title': snapshot.state|trans, 'context': snapshot.state}}) }}

                {{ appImport.dashboardKpi({'title': 'start_time'|trans, 'badge': {'title': snapshot.startTime|human_datetime}}) }}

                {{ appImport.dashboardKpi({'title': 'end_time'|trans, 'badge': {'title': snapshot.endTime|human_datetime}}) }}

                {{ appImport.dashboardKpi({'title': 'duration'|trans, 'badge': {'title': snapshot.duration}}) }}

                {% if is_granted('REPOSITORIES_LIST', 'repository') %}
                    {{ appImport.dashboardKpi({'title': 'repository'|trans, 'badge': {'title': snapshot.repository, 'link': path('repositories_read', {'repository': snapshot.repository})}}) }}
                {% else %}
                    {{ appImport.dashboardKpi({'title': 'repository'|trans, 'badge': {'title': snapshot.repository}}) }}
                {% endif %}

                {{ appImport.dashboardKpi({'title': 'version'|trans, 'badge': {'title': snapshot.version}}) }}

                {% if snapshot.metadata['policy'] is defined %}
                    {% if is_granted('SLM_POLICIES_LIST', 'slm_policy') %}
                        {{ appImport.dashboardKpi({'title': 'slm_policy'|trans, 'badge': {'title': snapshot.metadata['policy'], 'link': path('slm_read', {'name': snapshot.metadata['policy']})}}) }}
                    {% else %}
                        {{ appImport.dashboardKpi({'title': 'slm_policy'|trans, 'badge': {'title': snapshot.metadata['policy']}}) }}
                    {% endif %}
                {% endif %}
            </div>

            {% if 0 < snapshot.indices|length %}
                {% embed 'Embed/table_embed.html.twig' %}
                    {% import 'Import/app_import.html.twig' as appImport %}

                    {% block thead %}
                        <tr>
                            <th>{{ 'indices'|trans }}</th>
                        </tr>
                    {% endblock %}

                    {% block tbody %}
                        {% for index in snapshot.indices %}
                            <tr>
                                <td>{{ index }}</td>
                            </tr>
                        {% endfor %}
                    {% endblock %}
                {% endembed %}
            {% endif %}
        {% endblock %}
    {% endembed %}
{% endblock %}
